import { LoginParm } from '@/api/user/UserModel'
import { getCurrentInstance } from 'vue'
import { useStore } from '@/store'
import { useRouter } from 'vue-router'
export default function useLoginRequest() {
  const store = useStore()
  let router = useRouter()
  const { proxy } = getCurrentInstance() as any
  const login = (loginModel: LoginParm) => {
    proxy.$refs.loginFormRef.validate((valid: boolean) => {
      if (valid) {
        store.dispatch('user/login', loginModel).then((res: any) => {
          const userInfo = store.getters['user/getUserInfo']
          router.push({ path: '/' })
        })
      }
    })
  }
  return {
    login
  }
}
